<?php
/**
 * Created by PhpStorm.
 * User: guokunsheng
 * Date: 2018/6/8
 * Time: 11:28
 */

namespace app\rectification\controller;


use app\check\controller\Check;
use app\common\lib\PushQueue;
use \app\common\lib\Rectification;
use app\common\model\Goods;
use app\common\model\Recode;
use app\common\model\Rectification as RectificationModel;
use app\common\model\RectificationResult;
use think\Cache;
use think\Db;
use think\Log;

/**
 * @title 校准生辰相关接口
 * @desc 根据用户人生大事件来校正出生时间
 * @url
 * @version 1.0
 * @readme /doc/md/rectification/base.md
 * Class Index
 */
class Index extends Check
{
    protected $restActionList = ['index', 'read', 'save', 'update', 'delete', 'start', 'use'];

    /**
     * @title 查看历史记录 加入订单id字段######
     * @method GET
     * @desc /rectifications
     * @readme /doc/md/rectification/index.md
     */
    public function index()
    {

        if (!request()->isGet())
        {
            return show(config('code.error'), '未知操作', [], 403);
        }
        // 用户id
        $uid = $this->user['id'];
        // 判断订单是否超时
//        check_overtime($uid);
        // 页码
        $page = input('get.page/d', 1);
        // 要查询的字段
        $field = 'id,status,start_time,end_time,create_time';
        $where = ['uid' => $uid, 'is_del' => 0];
        $order = 'id DESC';
        try
        {
            //判断是否是applePay
            if ($this->is_apple_pay)
            {
                $goods = $this->apple_goods['rec_goods'];
            } else
            {

                $goods = (new Goods())->getGoodsRec(['id' => 1]);
            }

            $data = (new RectificationModel())
                ->field($field)
                ->where($where)
                ->order($order)
                ->group('id')
                ->paginate(10, false, ['page' => $page])->toArray();
        }
        catch (\Exception $e)
        {
            $data['data'] = [];
        }

        if (!empty($data['data']))
        {
            $reids = [];
            $arr = [];
            foreach ($data['data'] as $k => $datum)
            {
                //获取活动折扣
                $activeDiscount = active($goods['id']);
                if ($activeDiscount['discount'] && !$this->is_apple_pay)
                {
                    $datum['now_prize'] = sprintf('%.2f', $goods['now_prize'] * $activeDiscount['discount']);
                } else
                {
                    $datum['now_prize'] = sprintf("%.2f", $goods['now_prize']);
                }
                $datum['or_prize'] = sprintf("%.2f", $goods['or_prize']);
                $datum['order_id'] = null;
                $datum['trade_type'] = null;
                $arr[$datum['id']] = $datum;
                $reids[] = $datum['id'];
            }
            $reids = implode(',', $reids);

            $orders = Db::query(/** @lang text */
                "
                       SELECT o.id,o.trade_type,o.order_id,o.reid FROM app_orders o inner join (SELECT substring_index(group_concat(id order by id desc),',',1) id from app_orders  group by reid) o2 on o.id=o2.id where o.reid in ($reids);
                ");

            foreach ($orders as $o)
            {
                $arr[$o['reid']]['order_id'] = $o['order_id'];
                $arr[$o['reid']]['trade_type'] = $o['trade_type'];
            }

            $data['data'] = array_values($arr);

            return show(config('code.success'), '查看成功', $data);

        } else
        {
            return show(config('code.success'), '您还没有校正过哦，去矫正吧~');
        }
    }

    /**
     * @title 查看历史  加入订单id字段######
     * @method GET
     * @desc /rectification
     * @readme /doc/md/rectification/read.md
     */
    public function read()
    {
        if (!request()->isGet())
        {
            return show(config('code.error'), '未知操作', [], 403);
        }
        // 校准生辰id
        $id = input('get.reid/d');
        // 用户id
//        $uid = $this->user['id'];
        // 要排除的字段
        $field = ['uid', 'update_time'];

        // 订单金额信息
        $gid = 1;// 校准生辰

        try
        {
            //判断是否是applePay
            if ($this->is_apple_pay)
            {
                $goods = $this->apple_goods['rec_goods'];
            } else
            {

                $goods = (new Goods())->getGoodsRec(['id' => 1]);
            }

        }
        catch (\Exception $e)
        {
            return show(config('code.error'), '获取校准生辰商品信息失败');
        }

        if (!$goods || empty($goods))
        {
            return show(config('code.error'), '商品不存在');
        }
        try
        {
            $data = RectificationModel::get(['id' => $id]);
            if (!$data || $data['uid'] != $this->user['id'])
            {
                return show(config('code.error'), '数据不存在');
            }
            $data->hidden($field);
            // 事件
            $data['events'] = $data->events()->order('id ASC')->select();
            // 校正结果
            $data['result'] = $data->result()->field('id,time,score,status')->select();
            $return = 0;

            //因订单删除后,消息中心还可以进入校准生辰详情,所以要确保,$orders有值
            //获取已支付的订单信息
            $orders = RectificationModel::hasWhere('Orders', ['reid' => $id, 'pay_time' => ['>', 0]])->field('order_id,trade_type,pay_time,return_time,total_amount')->find();
            if (!$orders)
            {
                $orders = RectificationModel::hasWhere('Orders', ['reid' => $id, 'is_del' => 0])->field('order_id,trade_type,pay_time,return_time,total_amount')->find();
            }

            //获取活动折扣
            $activeDiscount = active($goods['id']);
            if ($activeDiscount['discount'] && !$this->is_apple_pay)
            {
                $data['now_prize'] = sprintf("%.2f", $goods['now_prize'] * $activeDiscount['discount']);
            } else
            {
                $data['now_prize'] = sprintf("%.2f", $goods['now_prize']);
            }
            $data['or_prize'] = sprintf("%.2f", $goods['or_prize']);
            if ($orders)
            {
                $return = $orders->return_time;
                $data['orders'] = [
                    'pay_time' => $orders->pay_time,
                    'order_id' => $orders->order_id,
                    'trade_type' => $orders->trade_type,
                    'total_amount' => $orders->total_amount,
                ];
                $data['now_prize'] = $orders['total_amount'];
            } else
            {
                $data['orders'] = [
                    'pay_time' => 0,
                    'order_id' => '',
                    'trade_type' => 0,
                    'total_amount' => $data['now_prize'],
                ];
            }
            $data['return_time'] = $return;
        }
        catch (\Exception $e)
        {
            return show(config('code.error'), '校准生辰信息获取失败');
        }

        $data = json_decode(json_encode($data, true), true);
        unset($data['orders']['status']);
        unset($data['orders']['return_time']);
        return show(config('code.success'), '查看成功', $data);
    }

    /**
     * @title 提交校准生辰
     * @method POST
     * @desc /rectification
     * @readme /doc/md/rectification/save.md
     * @return int status 0失败，无有效事件，无法继续提交 || 1成功，但是有效事件太少，影响校准生辰结果 || 2成功，等待支付
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \app\common\lib\exception\ApiException
     */
    public function save()
    {
        if (!request()->isPost())
        {
            return show(config('code.error'), '未知操作');
        }
        // 档案id
        $rid = input('post.rid/d');
        // 校正开始时间
        $start_time = input('post.start_time/d');
        // 校正结束时间
        $end_time = input('post.end_time/d');

        $timeDiff = $end_time - $start_time;

        if ($timeDiff < 0)
        {
            return show(config('code.error'), '开始时间不能大于结束时间');
        } elseif ($timeDiff == 0)
        {
            return show(config('code.error'), '开始时间不能等于结束时间');
        } elseif ($timeDiff > 7200)
        {
            return show(config('code.error'), '校正范围不可超过两小时');
        }

        // 校准生辰事件json
        $events = input('post.events/s');

        $ev = json_decode($events, true);

        $nowTime = time();

        foreach ($ev as $k => $v)
        {
            if ($v['time'] > $nowTime) return show(config('code.error'), '事件时间不能大于当前时间');
        }
        // json 转 array
        $events_array = json_decode($events, true);
        // 用户id
        $uid = $this->user['id'];
        // 检测传参
        if (!$uid || !$rid || !$events || empty($events_array))
        {
            return show(config('code.error'), '参数错误');
        }
        $recode = (new Recode())->getRecode(['id' => $rid]);

        if (!$recode || $recode['uid'] != $this->user['id'])
        {
            return show(config('code.error'), '档案不存在');
        }
        if (!$recode['isself'])
        {
            return show(config('code.error'), '当前仅限校正自己的档案');
        }
        // 矫正范围的中点时间
        $birth_time_mid = ($start_time + $end_time) / 2;

        // 有效事件判断
        $event_array = (new Rectification())->getValidEvents($events_array, $birth_time_mid, $recode);

        // 初始化有效事件数量
        $vaild_num = 0;
        // 有效事件++
        foreach ($event_array as $ea) if ($ea['status'] == 1) $vaild_num++;

        //判断是否是applePay
        if ($this->is_apple_pay)
        {
            $goods = $this->apple_goods['rec_goods'];
        } else
        {

            $goods = (new Goods())->getGoodsRec(['id' => 1]);
        }


        if (!$goods || empty($goods))
        {
            return show(config('code.error'), '商品不存在');
        }

        //获取活动折扣
        $activeDiscount = active($goods['id']);
        if ($activeDiscount['discount'] && !$this->is_apple_pay)
        {
            $goods['now_prize'] = sprintf("%.2f", $goods['now_prize'] * $activeDiscount['discount']);
        }

        $ret = [
            'status' => 0,
            'or_amount' => sprintf("%.2f", $goods['or_prize']),
            'total_amount' => sprintf("%.2f", $goods['now_prize']),
            'reid' => 0,
        ];
        //运营活动
//        if (checktime())
//        {
//            $ret['total_amount'] = 9.9;
//        }

        // 新校准生辰表入库  付款后 加入计算队列
//        $ZhunleRectification = new ZhunleRectification();
//        $ZhunleRectification->saveRectification();
//        $id = $ZhunleRectification->id;
//        $ZhunleRectification->events()->saveAll($event_array);


        // 入库  付款后 加入计算队列
        try
        {
            $insert_data = [
                'uid' => $uid,
                'rid' => $rid,
                'start_time' => $start_time,
                'end_time' => $end_time,
            ];
            $rectification = new RectificationModel;
            // 存入校准生辰表
            $rectification->isUpdate(false)->allowField(true)->save($insert_data);

            $id = $rectification->id;
            // 存入校准生辰事件表
            $rectification->events()->saveAll($event_array);
        }
        catch (\Exception $e)
        {
            return show(config('code.error'), $e->getMessage(), [], 500);
        }

        $ret['reid'] = (int)($id);

        if ($vaild_num < 1)
        {
            return show(config('code.success'), '无有效事件，会导致校正失败，请继续添加', $ret);
        }

        if ($vaild_num < 3)
        {
            $ret['status'] = 1;

            return show(config('code.success'), '有效事件太少，可能导致校正不准确，要继续提交吗', $ret);
        }

        $ret['status'] = 2;

        return show(config('code.success'), '待支付', $ret);
    }
    // 逐一验证用户指定出生范围内的星盘（每分钟一张盘），看对于所有有效事件，是否有四轴点的对应推进，每有一个记录1分，每张盘记录一个总得分
    // 如果有得分则可检测半有效事件是否成立，否则不检测
    // 半有效事件成立单独标记
    /**
     * @title 更新校准生辰
     * @method PUT
     * @desc /rectification
     * @readme /doc/md/rectification/update.md
     * @return int status 0失败，无有效事件，无法继续提交 || 1成功，但是有效事件太少，影响校准生辰结果 || 2成功，等待支付 || 3已支付
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \app\common\lib\exception\ApiException
     */
    public function update()
    {
        if (!request()->isPut())
        {
            return show(config('code.error'), '未知操作', [], 403);
        }
        // 主键id
        $id = input('param.reid/d');
        // 档案id
        $rid = input('param.rid/d');
        // 校正开始时间
        $start_time = input('param.start_time/d');
        // 校正结束时间
        $end_time = input('param.end_time/d');
        // 校准生辰事件json
        $events = input('param.events/s');
        // 检测传参 主键 || 档案id || 事件json字符串
        if (!$id || !$rid || !$events)
        {
            return show(config('code.error'), '参数错误1');
        }

        $timeDiff = $end_time - $start_time;

        if ($timeDiff < 0)
        {
            return show(config('code.error'), '开始时间不能大于结束时间');
        } elseif ($timeDiff == 0)
        {
            return show(config('code.error'), '开始时间不能等于结束时间');
        } elseif ($timeDiff > 7200)
        {
            return show(config('code.error'), '校正范围不可超过两小时');
        }

        $ev = json_decode($events, true);

        $nowTime = time();

        foreach ($ev as $k => $v)
        {
            if ($v['time'] > $nowTime) return show(config('code.error'), '事件时间不能大于当前时间');
        }

        // 获取用户id
        $recode = (new Recode())->getRecode(['id' => $rid]);

        if (!$recode || $recode['uid'] != $this->user['id'])
        {
            return show(config('code.error'), '档案不存在');
        }
        if (!$recode['isself'])
        {
            return show(config('code.error'), '当前仅限校正自己的档案');
        }
        // 矫正范围的中点时间
        $birth_time_mid = ($start_time + $end_time) / 2;
        // 所有的事件
        $events_array = json_decode($events, true);

        $event_array = (new Rectification())->getValidEvents($events_array, $birth_time_mid, $recode);

        // 初始化有效事件数量
        $vaild_num = 0;

        foreach ($event_array as $ea) if ($ea['status'] == 1) $vaild_num++;

        //判断是否是applePay
        if ($this->is_apple_pay)
        {
            $goods = $this->apple_goods['rec_goods'];
        } else
        {

            $goods = (new Goods())->getGoodsRec(['id' => 1]);
        }


        if (!$goods || empty($goods))
        {
            return show(config('code.error'), '商品不存在');
        }

        $ret = [
            'status' => 0,
            'or_amount' => sprintf("%.2f", $goods['or_prize']),
            'total_amount' => sprintf("%.2f", $goods['now_prize']),
            'reid' => 0,
        ];

        $order_status = 0;// 默认未支付

        $orders = RectificationModel::hasWhere('Orders', ['is_del' => 0, 'reid' => $id])->field('order_id,trade_type,pay_time,return_time,total_amount')->find();

        // 入库  付款后 加入计算队列
        try
        {
            $update_data = [
                'rid' => $rid,
                'start_time' => $start_time,
                'end_time' => $end_time,
            ];
            $rectification = RectificationModel::get($id);
            // 存入校准生辰表
            $rectification->isUpdate(true)->save($update_data);
            // 删除校准生辰事件表
            $rectification->events()->delete();
            // 存入校准生辰事件表
            $rectification->events()->saveAll($event_array);
            //更新校准生辰状态
//            RectificationModel::update(['status' => 0], ['id' => $id]);
            // 判断支付状态
            if ($orders && $orders->status)
            {
                // 已支付
                $order_status = 1;
            }
        }
        catch (\Exception $e)
        {
            return show(config('code.error'), $e->getMessage(), [], 500);
        }

        $ret['reid'] = (int)($id);
        $ret['order_status'] = $order_status;

        if ($vaild_num < 1)
        {
            return show(config('code.success'), '无有效事件，会导致校正失败，请继续添加', $ret);
        }

        if ($vaild_num < 3)
        {
            $ret['status'] = 1;

            return show(config('code.success'), '有效事件太少，可能导致校正不准确，要继续提交吗', $ret);
        }

        $ret['status'] = 2;

        return show(config('code.success'), '更新成功', $ret);
    }

    /**
     * @title 删除
     * @method DELETE
     * @readme /doc/md/rectification/delete.md
     * @throws \think\exception\DbException
     */
    public function delete()
    {
        if (!request()->isDelete())
        {
            return show(config('code.error'), '未知操作', '', 403);
        }
        $uid = $this->user['id'];

        $reid = input('param.reid/d');

        $rid = input('param.rid/d');

        if (!$uid || !$reid || !$rid)
        {
            return show(config('code.error'), '参数错误', '', 400);
        }

        $recode = (new Recode())->getRecode(['id' => $rid]);

        if (!$recode || $recode['uid'] != $this->user['id'])
        {
            return show(config('code.error'), '档案不存在');
        }

        $rectification = RectificationModel::get($reid);

        if (!$rectification || $rectification['uid'] != $this->user['id'])
        {
            return show(config('code.error'), '数据不存在');
        }

        if ($rectification['status'] == 1)
        {
            return show(config('code.error'), '正在计算中，不可删除', '', 200);
        }

        if (!$rectification || $rectification['rid'] != $rid || $rectification['uid'] != $uid)
        {
            return show(config('code.error'), '非法操作', '', 200);
        }
        // 进行软删除
//        $rectification->delete();
        try
        {
            (new \app\common\cachemodel\Rectification())->DelData($this->user['id'], $reid);
        }
        catch (\Exception $e)
        {
            Log::write('删除校准生辰失败：' . $e->getMessage() . '失败行数：' . $e->getLine(), 'error', true);
            return show(config('code.error'), $e->getMessage(), [], 500);
        }

        return show(config('code.success'), '删除成功', []);
    }

    /**
     * @title 开始校准生辰
     * @method POST
     * @desc /start_rectification
     * @readme /doc/md/rectification/start.md
     * @return array
     */
    public function start()
    {
        if (!request()->isPost())
        {
            return show(config('code.error'), '未知操作', '', 403);
        }
        // 检测是否支付了
        $reid = input('reid/d');// 校准生辰id

        if (!$reid)
        {
            return show(config('code.error'), '参数错误');
        }

        try
        {
            $rectification = RectificationModel::get(['id' => $reid]);
            if (!$rectification || $rectification['uid'] != $this->user['id'])
            {
                return show(config('code.error'), '数据不存在');
            }
            $event_array = $rectification->events()->select();
            $recode = Db::table('wechat_backup_07_18_14_43_00.app_recode')->find($rectification['rid']);

            $rectification->isUpdate(true)->save(['status' => 1]);// 更新校正状态 1 等待校正

            $orders = RectificationModel::hasWhere('Orders', ['is_del' => 0, 'reid' => $reid])->field('order_id,trade_type,pay_time,return_time,total_amount')->find();

            if ($orders && $orders->status)
            {
                $data = [
                    'oid' => $orders->id,
                    'order_id' => $orders->order_id,
                    'reid' => $reid,
                    'start_time' => $rectification['start_time'],
                    'end_time' => $rectification['end_time'],
                    'events' => $event_array,
                    'recode' => $recode
                ];
                $queueConfig = config('queue');
                queuePush($queueConfig['rectification_task'], $data, $queueConfig['rectification_queue'], $queueConfig['rectification_delay']);
            }
        }
        catch (\Exception $e)
        {
            return show(config('code.error'), $e->getMessage(), [], 500);
        }

        return show(config('code.success'), '开始校正，等待校正结果');
    }

    /**
     * @title 校准生辰采纳
     * @method POST
     * @desc /use_rectification
     * @readme /doc/md/rectification/use.md
     * @return array
     */
    public function use()
    {
        if (!request()->isPost())
        {
            return show(config('code.error'), '未知操作');
        }
        $uid = $this->user['id'];

        $id = input('id/d');// 采纳的结果id
        $reid = input('reid/d');// 校准生辰id

        if (!$uid || !$id || !$reid)
        {
            return show(config('code.error'), '参数错误');
        }

        $RecodeModel = new Recode();

        try
        {
            $rectification = RectificationModel::get($reid);
            if (!$rectification || $rectification['uid'] != $this->user['id'])
            {
                return show(config('code.error'), '数据不存在');
            }
            $recode = $RecodeModel->getRecode(['uid' => $uid, 'id' => $rectification->rid]);
            $rectification['result'] = $rectification->result()->where('id', $id)->find();
            $long_deg = $recode['long_deg'];
            $long_min = $recode['long_min'];
            $ew = $recode['ew'];
            $lat_deg = $recode['lat_deg'];
            $lat_min = $recode['lat_min'];
            $ns = $recode['ns'];
            $timezone = $recode['timezone'];
            $rid = $recode['id'];
        }
        catch (\Exception $e)
        {
            return show(config('code.error'), $e->getMessage());
        }

        $use_time = $rectification['result']['time'];// 采纳的时间
        $year = date('Y', $use_time);
        $month = date('m', $use_time);
        $day = date('d', $use_time);
        $hour = date('H', $use_time);
        $minute = date('i', $use_time);
        $is_summer = isSummerTime($hour, $minute, 0, $month, $day, $year) ? 1 : 0;// 是否为夏令时时间

        $Astro = new \app\astro\controller\Index();
        $longitude = ($long_deg + $long_min / 60) * $ew;
        $latitude = ($lat_deg + $lat_min / 60) * $ns;
        // 查询当前星盘日月水金火木土等星落座落宫存入数据库
        $astro_data = $Astro->getTheRecodeAstro($year, $month, $day, $hour, $minute, $longitude, $latitude, $timezone);

        try
        {
            // 先将已采用的还原为未采用
//            $rectification->result()->where('status', 1)->update(['status' => 0]);
            RectificationResult::update(['status' => 0], ['status' => 1]);
            $rectification->result()->where('id', $id)->update(['status' => 1]);

            $RecodeModel->where('id', $rid)->update([
                'year' => $year,
                'month' => $month,
                'day' => $day,
                'hour' => $hour,
                'minute' => $minute,
                'is_summer' => $is_summer,
            ]);// 更新档案里的相关
            // 更新档案的缓存 暂时为删除当前档案缓存
            Cache::rm('recode_' . $rid);
            Cache::rm('recode_lists_' . $uid);

            Db::table('wechat_backup_07_18_14_43_00.app_recode_info')->where('rid', $rid)->update(['last_time' => time()]);// 更新档案最后时间

            Db::table('wechat_backup_07_18_14_43_00.app_recode_astro')->where(['rid' => $rid])->update($astro_data);// 更新档案行星数据
        }
        catch (\Exception $e)
        {
            return show(config('code.error'), $e->getMessage());
        }

        $mids = [];

        try
        {
            // TODO 添加消息到消息中心封装
            // 获取校准生辰对应的消息id
            $reids = Db::table('wechat_backup_07_18_14_43_00.app_message_center')->field('id')->where('reid', $reid)->find();

            if ($reids || !empty($reids))
            {
                // 获取已读的消息id
                $msg = Db::table('app_user_msg')->where('uid', $uid)->field('mid')->select();
                if ($msg || !empty($msg))
                {
                    foreach ($msg as $k => $v)
                    {
                        $mids[] = $v['mid'];
                    }
                    if (!in_array($reids['id'], $mids))
                    {
                        Db::table('app_user_msg')->insert(['mid' => $reids['id'], 'uid' => $uid]);
                    }
                } else
                {
                    Db::table('app_user_msg')->insert(['mid' => $reids['id'], 'uid' => $uid]);
                }

            }
        }
        catch (\Exception $e)
        {
            return show(config('code.error'), $e->getMessage());
        }

        $astro_data['rid'] = $rid;
        $astro_data['year'] = $year;
        $astro_data['month'] = $month;
        $astro_data['day'] = $day;
        $astro_data['hour'] = $hour;
        $astro_data['minute'] = $minute;
        $astro_data['is_summer'] = $is_summer;

        return show(config('code.success'), '采纳成功', $astro_data);
    }

    /**
     * 参数规则
     * @name //字段名称
     * @type //类型
     * @require 是否必须
     * @default 默认值
     * @desc 说明
     * @range 范围
     * @return array
     */
    public static function getRules()
    {
        $rules = [
            'index' => [
                'access_token' => ['name' => 'access_token', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '接口访问凭证', 'range' => '32位',],
                'ucid' => ['name' => 'ucid', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '用户ucid', 'range' => '32位',],
                'page' => ['name' => 'page', 'type' => 'int', 'require' => 'false', 'default' => '1', 'desc' => '页码', 'range' => '默认为第一页',],
            ],
            'read' => [
                'access_token' => ['name' => 'access_token', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '接口访问凭证', 'range' => '32位',],
                'ucid' => ['name' => 'ucid', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '用户ucid', 'range' => '32位',],
                'reid' => ['name' => 'reid', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '校正记录id', 'range' => '',],
            ],
            'save' => [
                'access_token' => ['name' => 'access_token', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '接口访问凭证', 'range' => '32位',],
                'ucid' => ['name' => 'ucid', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '用户ucid', 'range' => '32位',],
                'rid' => ['name' => 'rid', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '档案id', 'range' => '仅限自己的档案',],
                'start_time' => ['name' => 'start_time', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '校正开始时间', 'range' => '秒为单位的时间戳',],
                'end_time' => ['name' => 'end_time', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '校正结束时间', 'range' => '秒为单位的时间戳',],
                'events' => ['name' => 'events', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '校正事件/json', 'range' => '[{"time":1528684429,"type":1,"desc":""}]',],
            ],
            'update' => [
                'access_token' => ['name' => 'access_token', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '接口访问凭证', 'range' => '32位',],
                'ucid' => ['name' => 'ucid', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '用户ucid', 'range' => '32位',],
                'rid' => ['name' => 'rid', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '档案id', 'range' => '仅限自己的档案',],
                'reid' => ['name' => 'reid', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '校正记录id', 'range' => '',],
                'start_time' => ['name' => 'start_time', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '校正开始时间', 'range' => '秒为单位的时间戳',],
                'end_time' => ['name' => 'end_time', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '校正结束时间', 'range' => '秒为单位的时间戳',],
                'events' => ['name' => 'events', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '校正事件/json', 'range' => '[{"time":1528684429,"type":1,"desc":""}]',],
            ],
            'delete' => [
                'access_token' => ['name' => 'access_token', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '接口访问凭证', 'range' => '32位',],
                'ucid' => ['name' => 'ucid', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '用户ucid', 'range' => '32位',],
                'rid' => ['name' => 'rid', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '档案id', 'range' => '仅限自己的档案',],
                'reid' => ['name' => 'reid', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '校正记录id', 'range' => '',],
            ],
            'use' => [
                'access_token' => ['name' => 'access_token', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '接口访问凭证', 'range' => '32位',],
                'ucid' => ['name' => 'ucid', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '用户ucid', 'range' => '32位',],
                'id' => ['name' => 'id', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '采纳的结果id', 'range' => '',],
                'reid' => ['name' => 'reid', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '校准生辰id', 'range' => '',],
            ],
            'start' => [
                'access_token' => ['name' => 'access_token', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '接口访问凭证', 'range' => '32位',],
                'ucid' => ['name' => 'ucid', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '用户ucid', 'range' => '32位',],
                'reid' => ['name' => 'reid', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '校准生辰id', 'range' => '',],
            ],
        ];
        return $rules;
    }
}
